import request from '@/util/require'
import { usePortStore } from '@/stores/index'
import axios from 'axios'
import { computed } from 'vue'
const { getPort, getUserInfo, setPort, setUrl,afterURL } = usePortStore()
// const port = getPort() + 1 + '/ai_pocket'
//wifi列表地址
const baseURL = "http://192.168.150.1:8000"
//登录基地址
const loginURL = "http://47.94.1.69:6500"
//登录后的地址
// const afterURL = 'http://47.94.1.69:'·
const pocketURL = computed(() => {
  // return "http://47.94.1.69:" + (getPort() + 1)
  const afterURL = usePortStore().afterURL
  return "http://" + afterURL + ":8000"
})


const casaOSURL = computed(() => {
  // return "http://47.94.1.69:" + (getPort() + 1)
  const afterURL = usePortStore().afterURL
  return "http://" + afterURL + ":81"
})

/** ************wifi列表************/
export const wifiList = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'get',
  url: '/wifi-list',
})
export const wifiInfo = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'get',
  url: '/wifi-info',
})
/** ************wifi列表************/
export const connectWifi = (data) => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/connect-wifi',
  data
})
export const login = (data) => request({
  baseURL: loginURL,
  method: 'get',
  url: '/activate/?device_id=' + data.deviceId
})

//port
export const query = (data) => request({
  // baseURL: baseURL,
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/query',
  data,
  headers: {
    'Content-Type': 'application/json',
  },
  onDownloadProgress: (res) => {
    console.log(res)
  }
})


//搜索文件
export const getSearch = (data) => request({
  // baseURL: baseURL,
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/search',
  headers: {
    'Content-Type': 'application/json'
  },
})
//文件上传
export const saveFile = (data) => request({
  // baseURL: baseURL,
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/saveFile',

})

//创建ppt http://192.168.150.1:8000/ai_pocket/createPPT
export const createPPT = (data) => request({
  // baseURL: baseURL,
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/createReport'
})


export const downWord = (data) => request({
  responseType: 'blob',
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/downloadDocument',
  headers: {
    'Content-Type': 'application/json'
  },
})


//下载ppt http://192.168.150.1:8000/ai_pocket/GeneratePPT
export const GeneratePPT = (data, currentRate) => request({
  // baseURL: "http://localhost:3000",
  onDownloadProgress: function (progressEvent) {
    // 处理原生进度事件
    currentRate.value = + (progressEvent.loaded / progressEvent.total * 100).toFixed(2)

  },
  responseType: 'blob',
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/GenerateReport'
  // url: '/download'
})

export const GenerateReportFilePath = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  onDownloadProgress: function (progressEvent) {
    // 处理原生进度事件
    currentRate.value = + (progressEvent.loaded / progressEvent.total * 100).toFixed(2)

  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/GenerateReportFilePath'
  // url: '/download'
})
// `http://47.94.1.69:${(getPort() + 1)}/v3/file?token=${ usePortStore().getUserInfo().token.access_token}&path=`

export const downloadFile = (filePath) => {
  window.open(casaOSURL.value + '/v3/file' + '?token=' + usePortStore().getUserInfo().token.access_token + '&' + 'path=' + filePath)
}



export const downloadFiles = (files) => {
  window.open(casaOSURL.value + '/v1/batch' + '?token=' + usePortStore().getUserInfo().token.access_token + '&' + 'files=' + files)
}




//博客生成 http://192.168.150.1:8000/ai_pocket/textPolish
export const textPolish = (data) => request({
  // baseURL: baseURL,
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/textPolish'
})

export const nasLogin = (data) => {
  return request({
    baseURL: casaOSURL.value,
    method: 'post',
    data,
    url: '/v1/users/login'
  })
}

// http://47.94.1.69:6115/v2/casaos/file/upload    图片上传
export const uploadImg = (data) => {
  const token = usePortStore().getUserInfo().token.access_token
  return request({
    baseURL: casaOSURL.value,
    method: 'post',
    data,
    url: '/v2/casaos/file/upload',
    headers: {
      authorization: token
    }
  })
}
export const listNote = (data) => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/listNote'
})
export const filtration = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/filtration'
})
export const getAllPeople = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/getAllPeople'
})

export const reNameId = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/rename_id'
})

export const getPeopelByTimeSort = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/getpeopelByTimeSort'
})


export const getAllPhotoTag = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/get_all_photo_tag'
})


export const addIdAttribute = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/add_id_attribute'
})


export const removeIdAttribute = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/remove_id_attribute'
})

export const getAllImagesByTimeSort = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/getAllImagesByTimeSort'
})
export const getAllCityInfo = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/getAllCityInfo'
})
export const getCityByTimeSort = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/getCityByTimeSort'
})
export const getAllTags = () => request({
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  url: '/getAllTags'
})

export const getTagsImagesByTimeSort = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  method: 'post',
  data,
  url: '/getTagsImagesByTimeSort'
})

export const searchPhoto = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/search_photo'
})
export const getTagImagesByTimeSort = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/getTagImagesByTimeSort'
})
export const getPeopleIdAttribute = (data) => request({
  headers: {
    'Content-Type': 'application/json'
  },
  baseURL: pocketURL.value + '/ai_pocket',
  data,
  method: 'post',
  url: '/get_people_id_attribute'
})

export const testNetwork = (ip) => request({
  baseURL: 'http://' + ip + ':8000' + '/ai_pocket',
  method: 'get',
  url: '/wifi-list',
})


export function getImgUrl (filePath) {
  return casaOSURL.value + '/v3/file' + '?token=' + usePortStore().getUserInfo().token.access_token + '&' + 'path=' + filePath
}
